package org.game.gobang.client.support;

import javafx.fxml.FXMLLoader;
import javafx.geometry.Insets;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import org.game.constant.APIConstant;
import org.game.gobang.client.constant.ClientConstant;

public abstract class GobangMap extends GobangInit {
    @Override
    public void initMain(VBox main) {
        ClientConstant.map = new GridPane();
        main.setPadding(new Insets(5));

        ClientConstant.refreshMap();

        main.getChildren().add(ClientConstant.map);
    }

    @Override
    protected void initToolBar(VBox main) {
        GridPane toolBar = new GridPane();
        toolBar.setPadding(new Insets(5));
        toolBar.setHgap(5);
        toolBar.setVgap(5);

        toolBar.add(new Label("房间名"), 0, 0);
        ClientConstant.name = new Label("未加入");
        toolBar.add(ClientConstant.name, 1, 0);

        toolBar.add(new Label("玩家"), 2, 0);
        ClientConstant.playerLabel = new Label("未加入");
        toolBar.add(ClientConstant.playerLabel, 3, 0);

        Button createButton = new Button("创建房间");
        createButton.setOnAction(action -> {
            new CreateRoomBox("创建房间");
        });
        toolBar.add(createButton, 0, 1);
        Button joinButton = new Button("加入房间");
        joinButton.setOnAction(action -> {
            try {
                Stage stage = new Stage();
                Parent root = FXMLLoader.load(getClass().getResource("/fxml/room.fxml"));
                stage.setTitle("加入房间");
                stage.setScene(new Scene(root, 300, 400));
                stage.show();
            } catch (Exception e) {

            }
        });
        toolBar.add(joinButton, 1, 1);
        toolBar.add(new Button("离开房间"), 2, 1);

        main.getChildren().add(toolBar);
    }
}
